package force;

import assembly.Mass;
import java.util.Scanner;
import simulation.SpringiesConstants;
import simulation.Model;
import util.Vector;


/**
 * 
 * @author Scott Valentine
 * @author Dagbedji Fagnisse
 *         A viscous drag force which applies a resistive force
 *         on masses proportional to their velocity.
 */
public class Viscosity extends Force {

    private static final String KEYWORD = SpringiesConstants.VISCOSITY_KEYWORD;
    private static final int TOGGLE_KEY = SpringiesConstants.VISCOSITY_TOGGLE;
    private double myConstant;

    /**
     * Main Constructor.
     * 
     * @param constant is the "drag factor"
     */
    public Viscosity (double constant) {
        myConstant = constant;
        toggle();
    }

    /**
     * Default constructor. Builds a sample Viscosity object.
     */
    public Viscosity () {
        this(0.0);
        // don't forget to untoggle force
        toggle();
    }

    /**
     * Compute the value of the force on a specific mass. Viscosity being a drag
     * force, the value is proportional and opposite to the velocity.
     * 
     * @param m
     *        the mass for which the force is to be computed.
     */
    public Vector getForceOn (Mass m) {

        if (!isForceOn()) { return new Vector(); }

        Vector currentVelocity = m.getVelocity();
        double magnitude = myConstant * currentVelocity.getMagnitude();
        Vector force = new Vector(currentVelocity.getDirection(), magnitude);
        force.negate();
        return force;
    }

    @Override
    public Force load (Scanner line, Model model) {
        double constant = line.nextDouble();
        return new Viscosity(constant);
    }

    @Override
    public String getKeyword () {
        return KEYWORD;
    }

    @Override
    public int getToggleKey () {
        return TOGGLE_KEY;
    }
}
